<template><div><h2 id="常用配置" tabindex="-1"><a class="header-anchor" href="#常用配置"><span>常用配置</span></a></h2>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#7F848E;font-style:italic"># 设置</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> config</span><span style="color:#D19A66"> --global</span><span style="color:#98C379"> user.name</span><span style="color:#98C379"> "你的用户名"</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> config</span><span style="color:#D19A66"> --global</span><span style="color:#98C379"> user.email</span><span style="color:#98C379"> "你的邮箱地址"</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> config</span><span style="color:#D19A66"> --global</span><span style="color:#98C379"> http.proxy</span><span style="color:#98C379"> 127.0.0.1:7897</span><span style="color:#7F848E;font-style:italic"> # 全局http代理</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> config</span><span style="color:#D19A66"> --global</span><span style="color:#98C379"> https.proxy</span><span style="color:#98C379"> 127.0.0.1:7897</span><span style="color:#7F848E;font-style:italic"> # 全局https代理</span></span>
<span class="line"></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># 取消</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> config</span><span style="color:#D19A66"> --global</span><span style="color:#D19A66"> --unset</span><span style="color:#98C379"> http.proxy</span><span style="color:#7F848E;font-style:italic"> # 取消HTTP代理</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> config</span><span style="color:#D19A66"> --global</span><span style="color:#D19A66"> --unset</span><span style="color:#98C379"> https.proxy</span><span style="color:#7F848E;font-style:italic"> # 取消HTTPS代理</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="局部代理设置" tabindex="-1"><a class="header-anchor" href="#局部代理设置"><span>局部代理设置</span></a></h2>
<h3 id="前言" tabindex="-1"><a class="header-anchor" href="#前言"><span>前言</span></a></h3>
<p>Git如果设置全局代理，则每次同步代码时都需要开启VPN。即使是国内的站点或者自己的Git Lab，不开启VPN时也会出现超时。</p>
<h3 id="期望" tabindex="-1"><a class="header-anchor" href="#期望"><span>期望</span></a></h3>
<p>默认不使用代理，特定站点才使用代理。</p>
<h3 id="设置" tabindex="-1"><a class="header-anchor" href="#设置"><span>设置</span></a></h3>
<ol>
<li>取消全局代理</li>
</ol>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> config</span><span style="color:#D19A66"> --global</span><span style="color:#D19A66"> --unset</span><span style="color:#98C379"> http.proxy</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> config</span><span style="color:#D19A66"> --global</span><span style="color:#D19A66"> --unset</span><span style="color:#98C379"> https.proxy</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><ol start="2">
<li>单独设置特定站点需要代理（如github.com）</li>
</ol>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> config</span><span style="color:#D19A66"> --global</span><span style="color:#98C379"> http.https://github.com.proxy</span><span style="color:#98C379"> http://代理地址:端口</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> config</span><span style="color:#D19A66"> --global</span><span style="color:#98C379"> https.https://github.com.proxy</span><span style="color:#98C379"> https://代理地址:端口</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><ol start="3">
<li>刷新DNS缓存</li>
</ol>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">ipconfig</span><span style="color:#98C379"> /flushdns</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p><strong>如果要取消特定站点的代理</strong></p>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> config</span><span style="color:#D19A66"> --unset</span><span style="color:#D19A66"> --global</span><span style="color:#98C379"> http.https://github.com.proxy</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="效果" tabindex="-1"><a class="header-anchor" href="#效果"><span>效果</span></a></h3>
<p>如果开启VPN，所有站点都能正常同步代码。如果关闭VPN，github.com超时，其它站点正常。</p>
<h2 id="常用命令" tabindex="-1"><a class="header-anchor" href="#常用命令"><span>常用命令</span></a></h2>
<h3 id="建立本地仓库" tabindex="-1"><a class="header-anchor" href="#建立本地仓库"><span>建立本地仓库</span></a></h3>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> init</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="链接远程数据库" tabindex="-1"><a class="header-anchor" href="#链接远程数据库"><span>链接远程数据库</span></a></h3>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> remote</span><span style="color:#98C379"> add</span><span style="color:#ABB2BF"> [alias] [url] </span><span style="color:#7F848E;font-style:italic"># alias 你为仓库起的别名 url 远程仓库地址</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> remote</span><span style="color:#7F848E;font-style:italic"> # 可以查看链接了多少远程仓库</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="本地提交代码" tabindex="-1"><a class="header-anchor" href="#本地提交代码"><span>本地提交代码</span></a></h3>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> add</span><span style="color:#98C379"> .</span><span style="color:#7F848E;font-style:italic"> #将数据添加到缓冲区中</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> commit</span><span style="color:#D19A66"> -m</span><span style="color:#98C379"> "提示信息"</span><span style="color:#7F848E;font-style:italic"> # 为此次提交写好提交信息</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> push</span><span style="color:#D19A66"> -u</span><span style="color:#ABB2BF"> [alias][branch name] </span><span style="color:#7F848E;font-style:italic"># 将代码提交到远程仓库中某一个分支 如果加上-u 这个选项则后面默认推送到这个分支上，如果不加则每次都要输出</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="本地pull代码" tabindex="-1"><a class="header-anchor" href="#本地pull代码"><span>本地pull代码</span></a></h3>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> pull</span><span style="color:#ABB2BF"> [alias][branch name] </span><span style="color:#7F848E;font-style:italic">#从远程仓库的某一分支中，拉取代码 小心有冲突</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="分支操作" tabindex="-1"><a class="header-anchor" href="#分支操作"><span>分支操作</span></a></h3>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> branch</span><span style="color:#7F848E;font-style:italic"> #查看分支命令</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> branch</span><span style="color:#ABB2BF"> [branch </span><span style="color:#98C379">name]</span><span style="color:#7F848E;font-style:italic"> #创建分支命令</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> checkout</span><span style="color:#ABB2BF"> [branch </span><span style="color:#98C379">name]</span><span style="color:#7F848E;font-style:italic"> #切换分支命令</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> merge</span><span style="color:#ABB2BF"> [branch </span><span style="color:#98C379">name]</span><span style="color:#7F848E;font-style:italic"> #合并分支命令,将当前分支与命令中的分支进行合并</span></span>
<span class="line"><span style="color:#61AFEF">git</span><span style="color:#98C379"> branch</span><span style="color:#D19A66"> -d</span><span style="color:#ABB2BF">  [branch </span><span style="color:#98C379">name]</span><span style="color:#7F848E;font-style:italic"> #删除分支命令</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="命令图" tabindex="-1"><a class="header-anchor" href="#命令图"><span>命令图</span></a></h3>
<p><img src="@source/常用开发知识总结/git命令图.png" alt=""></p>
</div></template>


